﻿// --------------------------------------------------------------------------------------------------------------------
// <copyright file="ExpressionEncoder.cs" company="StyleCop for ReSharper Development Team">
//   Copyright (c) StyleCop for ReSharper Development Team. All rights reserved.
// </copyright>
// <summary>
//   Provides access to the Expression Encoder through the standard encoding interface.
// </summary>
// --------------------------------------------------------------------------------------------------------------------

namespace BlinkBox.Encoding.Encoders.Expression
{
    #region Using Directives

    using EncodeProgressEventArgs = BlinkBox.Encoding.Encoders.EncodeProgressEventArgs;

    #endregion

    /// <summary>
    /// Provides access to the Expressio encoder through the standard encoding interface.
    /// </summary>
    public sealed class ExpressionEncoder : Encoder
    {
        #region Methods

        /// <summary>
        /// Chooses the encoding format for an encoder item.
        /// </summary>
        /// <param name="encoderItem">
        /// The encoder item.
        /// </param>
        /// <returns>
        /// The chosen outputFormat.
        /// </returns>
        private static OutputFormat ChooseOutputFormat(EncoderItem encoderItem)
        {
            BlinkBoxTrace.In(encoderItem);
            AssertArgument.IsNotNull("encoderItem", encoderItem);
            OutputFormat outputFormat = null;

            var profile = encoderItem.Profile;
            switch (profile.ContainerFormat)
            {
                case ContainerFormat.Asf:
                    outputFormat = new WindowsMediaOutputFormat
                        {
                            AudioProfile = new WmaAudioProfile { Bitrate = SelectBitrateControlForProfile(encoderItem.Profile.Audio.BitRateControl, encoderItem.Profile.Audio.BitRate / 1000) }, 
                            VideoProfile = new AdvancedVC1VideoProfile { Bitrate = SelectBitrateControlForProfile(encoderItem.Profile.Video.BitRateControl, encoderItem.Profile.Video.BitRate / 1000) }
                        };

                    break;
                case ContainerFormat.MP4:
                    outputFormat = new MP4OutputFormat
                        {
                            AudioProfile = new AacAudioProfile { Bitrate = SelectBitrateControlForProfile(encoderItem.Profile.Audio.BitRateControl, encoderItem.Profile.Audio.BitRate / 1000) }, 
                            VideoProfile = new MainH264VideoProfile { Bitrate = SelectBitrateControlForProfile(encoderItem.Profile.Video.BitRateControl, encoderItem.Profile.Video.BitRate / 1000) }
                        };

                    break;
            }

            return BlinkBoxTrace.Out(outputFormat);
        }

        #endregion
    }
}